// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import { GameEvent } from "./GameEvent";


const {ccclass, property} = cc._decorator;

@ccclass
export default class PlayerInfo {

public static _ins: PlayerInfo = null;
public static get ins() {
    if (PlayerInfo._ins == null) {
        PlayerInfo._ins = new PlayerInfo();
        let money = cc.sys.localStorage.getItem("money");
        if(money){
            this.ins.money = parseFloat(money);
        }else{
            cc.sys.localStorage.setItem("money",this.ins.money);
        }
    }
    return PlayerInfo._ins;
}
_money: number = 10000;
get money() {
    return this._money;
}
set money(money: number) {
    this._money = money;
    cc.sys.localStorage.setItem("money",this._money);
    cc.game.emit(GameEvent.PLAYER_MONEY_CHANGE, this._money);
}

getMoney() {
    return this._money;
}

subMoney(money: number) {
    this.money -= money;
}

addMoney(money: number) {
    this.money += money;
}

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {

    }

    // update (dt) {}
}
